package com.kgc.rb.common.configration;

import com.kgc.rb.common.redis.RedisAPI;
import lombok.Data;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class JedisPoolConfiguration {

    @Autowired
    private GenericObjectPoolConfig jedisPoolConfig;

    private String host;
    private int port;
    private int timeout;
    private String password;
    private int database;

    @Bean
    public JedisPool jedisPool(){
        JedisPool jedisPool = new JedisPool(jedisPoolConfig,host,port,timeout,password,database);
        return jedisPool;
    }

    @Bean
    public RedisAPI redisAPI(){
        RedisAPI redisAPI = new RedisAPI();
        redisAPI.setJedisPool(jedisPool());
        return redisAPI;
    }
}
